package JavaDay51;

public class DeleteString {
public static void main(String[] args) {
	   String original = "java woaijava,i liek jajavava,i enjoy java";
       String target = "java";
       String str = deleteString(original,target);

       System.out.println(str);
}

private static String deleteString(String original, String target) {
	String str = original;
	int index = 0;
	while ((index = str.indexOf(target)) != -1){
		str = removeTarget(str, target);
	}
	return str;
}

private static String removeTarget(String str, String target) {

	  StringBuilder result = new StringBuilder();
      int len = str.length();
      int targetLen = target.length();
      for (int i = 0; i < len; ) {
          if (i + targetLen <= len && str.substring(i, i + targetLen).equals(target)) {
              i += targetLen;
          } else {
              result.append(str.charAt(i));
              i++;
          }
      }
      return result.toString();
}
}
